﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_DSTinTuc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private void MessageBox(string msg)
    {
        Page.Controls.Add(new LiteralControl(
        "<script language='javascript'> window.alert('" + msg.Replace("'", "\\'") + "');location.href='DSTinTuc.aspx';</script>"));

    }
    protected void lkbtnThem_Click(object sender, EventArgs e)
    {
        TinTucBUS objTinTuc =
            new TinTucBUS(TGDDConfiguration.DbConnectionString);
        TinTucDTO ttDto = new TinTucDTO();
        ttDto.TieuDe = txtTieuDe.Text;
        ttDto.NoiDung = txtNoiDung.Content;
        ttDto.HinhMinhHoa = fileUploadHinhAnh.FileName;
        ttDto.IdNguoiDung = (Guid)Session["g_UserId"];

        if (objTinTuc.InsertTinTuc(ttDto))
        {
            string strBaseLocation = Server.MapPath("..") + "\\images\\tintuc\\" + fileUploadHinhAnh.FileName;

            if (fileUploadHinhAnh.PostedFile != null)
            {
                fileUploadHinhAnh.PostedFile.SaveAs(strBaseLocation);
            }

            MessageBox("Thêm thành công");
        }
        else
        {
            MessageBox("Thêm thất bại");
        }
    }
}
